/*
 * $Id: QEArrlSection.m 34 2009-04-21 20:24:55Z jon@bway.net $
 * Sleeper
 *
 * Created by Jon Gordon on 3/17/08
 * Copyright Jon Gordon.  All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining 
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to 
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#import "QEArrlSection.h"

#import "QECountry.h"

@interface QEArrlSection (private)
- (void)setSectionName:(NSString *)newSectionName;
- (void)setSectionAbbr:(NSString *)newSectionAbbr;
- (void)setCountry:(QECountry *)newCountry;
@end


@implementation QEArrlSection
- (id)initWithSectionName:(NSString *)newSectionName
              sectionAbbr:(NSString *)newSectionAbbr
                  country:(QECountry *)newCountry
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    self = [super init];
    if (nil != self) {
        [self setSectionName:newSectionName];
        [self setSectionAbbr:newSectionAbbr];
        [self setCountry:newCountry];
    } // if
    return self;
} // initWithSectionName:sectionAbbr:country:


- (NSString *)description
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [NSString stringWithFormat:@"%@ (%@)",
            [self sectionName],
            [self sectionAbbr]];
} // description


- (NSString *)sectionName
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[sectionName retain] autorelease];
} // sectionName


- (NSString *)sectionAbbr
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[sectionAbbr retain] autorelease];
} // sectionAbbr


- (QECountry *)country
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return [[country retain] autorelease];
} // country

- (void)dealloc
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    [sectionName release];
    [sectionAbbr release];
    [country release];
    
    [super dealloc];
} // dealloc

- (id)copyWithZone:(NSZone *)zone
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    QEArrlSection *newData = [[[self class] allocWithZone:zone]
                              initWithSectionName:[self sectionName]
                              sectionAbbr:[self sectionAbbr]
                              country:[self country]];
    return newData;
} // copyWithZone:

- (unsigned int)hash
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    static const unsigned int HASH_BASE = 17;
    static const unsigned int HASH_FACTOR = 37;
    
    unsigned int result = HASH_BASE;
    result = (result * HASH_FACTOR) + [[self sectionName] hash];
    result = (result * HASH_FACTOR) + [[self sectionAbbr] hash];
    result = (result * HASH_FACTOR) + [[self country] hash];
    
    return result;
} // hash

- (BOOL)isEqual:(id)anObject
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return ((self == anObject) ||
            ([[self sectionName] isEqual:[anObject sectionName]] &&
             [[self sectionAbbr] isEqual:[anObject sectionAbbr]] &&
             ([self country] == [anObject country])));
} // isEqual
@end


@implementation QEArrlSection (private)
- (void)setSectionName:(NSString *)newSectionName
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (sectionName != newSectionName) {
        [sectionName release];
        sectionName = [newSectionName copy];
    } // if
} // setSectionName:

- (void)setSectionAbbr:(NSString *)newSectionAbbr
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (sectionAbbr != newSectionAbbr) {
        [sectionAbbr release];
        sectionAbbr = [newSectionAbbr copy];
    } // if
} // setSectionAbbr:

- (void)setCountry:(QECountry *)newCountry
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    if (country != newCountry) {
        [country release];
        country = [newCountry retain];
    } // if
} // setCountry:
@end